/* 获取屏幕的参数信息 */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <linux/fb.h>

#define LCD_FB_DEV_FILE "/dev/fb0"

int main(int argc, char *argv[])
{
    struct fb_fix_screeninfo fb_fix;
    struct fb_var_screeninfo fb_var;
    int fb_fd;

    /* 打开 framebuffer设备 */
    fb_fd = open(LCD_FB_DEV_FILE, O_WRONLY);
    if (fb_fd < 0) {
        perror("open fb0 error");
        exit(-1);
    }
    /* 获取屏幕的参数信息 */
    if (ioctl(fb_fd, FBIOGET_FSCREENINFO, &fb_fix) < 0) {
        perror("ioctl FBIOGET_FSCREENINFO error");
        exit(-1);
    }
    if (ioctl(fb_fd, FBIOGET_VSCREENINFO, &fb_var) < 0) {
        perror("ioctl FBIOGET_VSCREENINFO error");
        exit(-1);
    }
    printf("分辨率：%d * %d\n", fb_var.xres, fb_var.yres);
    printf("像素深度 bpp: %d\n", fb_var.bits_per_pixel);
    printf("一行的字节数：%d\n", fb_fix.line_length);
    printf("像素格式: R<%d %d>G<%d %d>B<%d %d>\n", 
            fb_var.red.offset, fb_var.red.length, 
            fb_var.green.offset, fb_var.green.length,
            fb_var.blue.offset, fb_var.blue.length);
    /* 关闭设备文件退出程序 */
    close(fb_fd);
    exit(0);
}